package com.jingzhi.count;

import com.jingzhi.count.netty.CountSocketServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.net.InetSocketAddress;

@SpringBootApplication
@MapperScan("com.jingzhi.count.mapper")
public class CountApplication implements CommandLineRunner {

	@Value("${netty.port}")
	private Integer port;

	CountSocketServer		socketServer;

	public static void main(String[] args) {
		SpringApplication.run(CountApplication.class, args);

	}

	@Bean
	public CountSocketServer socketServer(){
		return socketServer = new CountSocketServer();
	}

	@Override
	public void run(String... strings) throws Exception {
		InetSocketAddress address = new InetSocketAddress(port);
		socketServer.start(address);
//		Runtime.getRuntime().addShutdownHook(new Thread(){
//			@Override
//			public void run() {
//				socketServer.destroy();
//			}
//		});
//
//		future.channel().closeFuture().syncUninterruptibly();
	}

}
